]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
appDisplay: Allow reordering folders
authorGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Wed, 24 Jun 2020 18:37:42 +0000 (15:37 -0300)
committerFlorian Müllner <florian.muellner@gmail.com>
Mon, 20 Jul 2020 16:13:20 +0000 (16:13 +0000)
Implement the methods to sort and query item positions
using the index in the GSettings key, and store the
updated positions when accepting the drop.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1284

js/ui/appDisplay.js

index e4799e0d850eaf90d5be66b6042329ea9c2225c6..a6c4d06434fb2dc8be5453752741a79d81728288 100644 (file)
@@ -1624,6 +1624,33 @@ class FolderView extends BaseAppView {
         return appIds;
     }
 
+    _getItemPosition(item) {
+        const appIds = this._getFolderApps();
+        const appIndex = appIds.indexOf(item.id);
+
+        if (appIndex === -1)
+            return [-1, -1];
+
+        const { itemsPerPage } = this._grid;
+        return [Math.floor(appIndex / itemsPerPage), appIndex % itemsPerPage];
+    }
+
+    _compareItems(a, b) {
+        const appIds = this._getFolderApps();
+
+        const aPosition = appIds.indexOf(a.id);
+        const bPosition = appIds.indexOf(b.id);
+
+        if (aPosition === -1 && bPosition === -1)
+            return a.name.localeCompare(b.name);
+        else if (aPosition === -1)
+            return 1;
+        else if (bPosition === -1)
+            return -1;
+
+        return aPosition - bPosition;
+    }
+
     // Overridden from BaseAppView
     animate(animationDirection) {
         this._grid.animatePulse(animationDirection);
@@ -1684,6 +1711,16 @@ class FolderView extends BaseAppView {
         return apps;
     }
 
+    acceptDrop(source) {
+        if (!super.acceptDrop(source))
+            return false;
+
+        const folderApps = this._orderedItems.map(item => item.id);
+        this._folder.set_strv('apps', folderApps);
+
+        return true;
+    }
+
     addApp(app) {
         let folderApps = this._folder.get_strv('apps');
         folderApps.push(app.id);